package com.note.chh.notebook.UI.stroke;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.note.chh.notebook.Model.Stroke;
import com.note.chh.notebook.R;
import com.note.chh.notebook.UI.base.BaseActivity;
import com.note.chh.notebook.Uitls.DialogUtils;
import com.note.chh.notebook.Uitls.EventReminderUtils;
import com.note.chh.notebook.Uitls.StrokeUtilsDao;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;

import butterknife.BindView;
import butterknife.OnClick;

//查看行程
public class CheckStrokeActivity extends BaseActivity {


    @BindView(R.id.topbar)
    QMUITopBar topbar;
    @BindView(R.id.mEdit_title)
    EditText mEditTitle;
    @BindView(R.id.mText_startTime)
    TextView mTextStartTime;
    @BindView(R.id.mLinear_startTime)
    LinearLayout mLinearStartTime;
    @BindView(R.id.mText_time)
    TextView mTextTime;
    @BindView(R.id.mLinear_time)
    LinearLayout mLinearTime;
    @BindView(R.id.mEdit_remark)
    EditText mEditRemark;
    @BindView(R.id.mLinear_delete)
    LinearLayout mLinearDelete;
    private long id = 0;
    private String title = "";
    @Override
    protected int bindLayout() {
        return R.layout.activity_check_stroke;
    }

    @Override
    public void initTopBar() {
        super.initTopBar();
        topbar.setBackgroundColor(getResources().getColor(R.color.app_color_blue));
        topbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        topbar.setTitle(getResources().getString(R.string.check_stroke));
    }

    @Override
    public void initView() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            Stroke stroke = StrokeUtilsDao.queryById(bundle.getLong("id"));
            id = stroke.getId();
            title = stroke.getTitle();
            mEditTitle.setText(stroke.getTitle());
            mTextStartTime.setText(stroke.getStartFormartTime());
            mTextTime.setText(stroke.getRemind());
            mEditRemark.setText(stroke.getRemark());
        }
        mEditTitle.setEnabled(false);
        mEditRemark.setEnabled(false);
    }

    @Override
    public void initData() {
        hideSoftInput();
    }

    @OnClick(R.id.mLinear_delete)
    public void onViewClicked() {
        DialogUtils.sureDialog(CheckStrokeActivity.this,"提示","要删除此日程吗?")
                .addAction("确认", new QMUIDialogAction.ActionListener() {
            @Override
            public void onClick(QMUIDialog dialog, int index) {
                EventReminderUtils.deleteCalendarEvent(CheckStrokeActivity.this,title);
                StrokeUtilsDao.deleteStroke(id);
                dialog.dismiss();
                finish();
            }
        }).show();
    }
}
